package GUI;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.*;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class Item extends JFrame {

	private JPanel contentPane;
	private AddIorP aip;
	private AssignToOrder ato;
	private Success suc;
	
	/**
	 * Create the frame.
	 */
	public Item(String s) {

		if(s.equals("new")){setTitle("Add item");}
		else{setTitle("Manage item");;}
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 240, 250);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblName = new JLabel("Name:");
		lblName.setBounds(10, 14, 46, 14);
		contentPane.add(lblName);
		
		JLabel lblPrice = new JLabel("Price:");
		lblPrice.setBounds(10, 39, 46, 14);
		contentPane.add(lblPrice);
		
		JLabel lblDiscount = new JLabel("Discount:");
		lblDiscount.setBounds(10, 68, 58, 14);
		contentPane.add(lblDiscount);
		
		JTextField txtItemName = new JTextField();
		txtItemName.setBounds(63, 11, 152, 20);
		contentPane.add(txtItemName);
		txtItemName.setColumns(10);
		
		JTextField txtItemDiscount = new JTextField();
		txtItemDiscount.setBounds(63, 65, 58, 20);
		contentPane.add(txtItemDiscount);
		txtItemDiscount.setColumns(10);
		
		JTextField txtItemPrice = new JTextField();
		txtItemPrice.setBounds(63, 36, 152, 20);
		contentPane.add(txtItemPrice);
		txtItemPrice.setColumns(10);
		
		JLabel lblPerCent = new JLabel("%");
		lblPerCent.setBounds(131, 68, 18, 14);
		contentPane.add(lblPerCent);
		//add-assign discount
		
		JButton btnAddDisc = new JButton("Add");
		btnAddDisc.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				ato = new AssignToOrder("dis","dis");
				ato.setVisible(true);
			}
		});
		btnAddDisc.setBounds(155, 64, 60, 20);
		contentPane.add(btnAddDisc);
		
		JButton btnCancel = new JButton("Cancel");
		btnCancel.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				MainMenu.getInstance().setVisible(true);
				dispose();
			}
		});
		btnCancel.setBounds(10, 177, 89, 23);
		contentPane.add(btnCancel);
		
		if(s.equals("new"))
		{
			JButton btnSave = new JButton("Save");
			btnSave.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					suc = new Success("cr", false);
					suc.setVisible(true);
					dispose();
				}
			});
			btnSave.setBounds(126, 177, 89, 23);
			contentPane.add(btnSave);
		}
		else
		{
			JButton btnSave = new JButton("Save");
			btnSave.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					suc = new Success("mng", false);
					suc.setVisible(true);
					dispose();
				}
			});
			btnSave.setBounds(126, 177, 89, 23);
			contentPane.add(btnSave);
		}
		
		
		JLabel lblComponents = new JLabel("Components:");
		lblComponents.setBounds(10, 93, 111, 14);
		contentPane.add(lblComponents);
		
		
		JButton btnAddComponents = new JButton("Add components");
		btnAddComponents.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				aip = new AddIorP("item");
				aip.setVisible(true);
			}
		});
		btnAddComponents.setBounds(84, 89, 130, 20);
		contentPane.add(btnAddComponents);

		JTextPane txtPaneComponents = new JTextPane(); //show added components
		txtPaneComponents.setEditable(false);
		txtPaneComponents.setText("???");
		txtPaneComponents.setBounds(10, 113, 204, 53);
		contentPane.add(txtPaneComponents);
	}

}
